/**
 * 门禁权限管理初始化
 */
var EntranceGuardRule = {
    id: "EntranceGuardRuleTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
EntranceGuardRule.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'ID', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '权限名称', field: 'ruleName', visible: true, align: 'center', valign: 'middle'},
        {title: '时段', field: 'timeInfo.name', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
EntranceGuardRule.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        EntranceGuardRule.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加门禁权限
 */
EntranceGuardRule.openAddEntranceGuardRule = function () {
    var index = layer.open({
        type: 2,
        title: '添加门禁权限',
        area: ['85%', '85%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/door/ENTRANCE/GUARD/RULE/add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看门禁权限详情
 */
EntranceGuardRule.openEntranceGuardRuleDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '系统参数详情',
            area: ['85%', '85%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/door/ENTRANCE/GUARD/RULE/edit/' + EntranceGuardRule.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除门禁权限
 */
EntranceGuardRule.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/door/ENTRANCE/GUARD/RULE/delete", function (data) {
            Feng.success("删除成功!");
            EntranceGuardRule.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id",this.seItem.id);
        ajax.start();
    }
};


/**
 * 打开门禁权限分配人员页面
 */
EntranceGuardRule.openSelectUserToRule = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '分配人员',
            area: ['85%', '85%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/door/ENTRANCE/GUARD/RULE/selectUserToRule/' + EntranceGuardRule.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 打开门禁权限分配门页面
 */
EntranceGuardRule.openSelectDoorToRule = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '分配门',
            area: ['85%', '85%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/door/ENTRANCE/GUARD/RULE/selectDoorToRule/' + EntranceGuardRule.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 打开门禁权限详细信息页面
 */
EntranceGuardRule.openDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '分配门',
            area: ['85%', '85%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/door/ENTRANCE/GUARD/RULE/detail/' + EntranceGuardRule.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 查询门禁权限列表
 */
EntranceGuardRule.search = function () {
    var queryData = {};
    queryData['ruleName'] = $("#ruleName").val();
    queryData['timeId'] = $("[id='timeInfo.id']").val();
    // console.log( $("[id='timeInfo.id']").val());
    EntranceGuardRule.table.refresh({query: queryData});
};
/**
 * 重置查询条件
 */
EntranceGuardRule.reset = function () {
    $('#ruleName').val('');
    $("[id='timeInfo.id']").val('');
    this.search();
};

$(function () {
    var defaultColunms = EntranceGuardRule.initColumn();
    var table = new BSTable(EntranceGuardRule.id, "/door/ENTRANCE/GUARD/RULE/list", defaultColunms);
    table.setPaginationType("server");
    EntranceGuardRule.table = table.init();

});
